package com.lht.testDemo;

import org.junit.Test;

import java.util.Arrays;
import java.util.Random;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-06-06
 */
public class ArraysDemo {


    @Test
    public void testParallel() {

        int[] arr = new int[1000000];
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(1000);
        }
        int[] copy = new int[arr.length];
        System.arraycopy(arr, 0, copy, 0, arr.length);
        long start = System.currentTimeMillis();
        Arrays.sort(copy);
        long end = System.currentTimeMillis();
        long count = end - start;
        System.out.println("sort:" + count);


        start = System.currentTimeMillis();
        Arrays.parallelSort(arr);
        end = System.currentTimeMillis();
        count = end - start;
        System.out.println("parallelSort:" + count);

//        for(int i=0;i<arr.length;i++){
//            boolean isEquals=copy[i]==arr[i];
//            System.out.println("Sort:"+copy[i]+",parallelSort:"+arr[i]+",equals:"+isEquals);
//        }
    }
}
